//
//  ZZCLawStatusController.m
//  ZZC-Finance
//
//  Created by a on 2017/8/16.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "ZZCLawStatusController.h"
#import "ZZCLawView.h"
#import "ZZCLawController.h"
@interface ZZCLawStatusController ()<UITextFieldDelegate,UIScrollViewDelegate>
@property (strong, nonatomic) ZZCLawView *lawView;
@property (strong, nonatomic) ZZCMenuView *menuViewA;
@property (strong, nonatomic) ZZCMenuView *menuViewB;
@property (strong, nonatomic) ZZCMenuView *menuViewC;
@property (copy,   nonatomic) NSString *name;

@property (strong, nonatomic) UILabel *stateLabel;

@property (strong, nonatomic) UIButton *bbtn;
@end

@implementation ZZCLawStatusController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"律师专家";
    [self messageShow];
    //状态栏
//    _stateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,CGRectGetHeight(_lawView.), ZZCScreenW, ZZCScreenH*0.175f)];
//    
//    _stateLabel.backgroundColor = [UIColor grayColor];
//    [self.lawView.bgScrollView addSubview:_stateLabel];

    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.lawView];
    self.lawView.bgScrollView.delegate = self;
    UIView *view = [[UIView alloc] initWithFrame:_lawView.bgScrollView.bounds];
    [self.lawView.bgScrollView addSubview:view];
    view.backgroundColor = [UIColor colorWithHex:0x000000 alpha:0.1];

//
    NSArray *arr = @[@"省级",@"市级",@"县级"];
    self.menuViewA = [[ZZCMenuView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.lawView.rankView.frame), ZZCScreenW, 132) contentArray:arr];
    __weak typeof (self) weakself = self;
    self.menuViewA.block = ^(BOOL isSeletct ,NSString *title){
        weakself.menuViewA.hidden = YES;
        if (title.length != 0) {
            [weakself.lawView.rankBtn setTitle:title forState:UIControlStateNormal];
        }
    };
//
    NSMutableArray *arr1 = [NSMutableArray new];
    for (int i = 1; i <= 80; i ++) {
        [arr1 addObject:[NSString stringWithFormat:@"%d",i]];
    }
    
    self.menuViewB = [[ZZCMenuView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.lawView.gradeView.frame), ZZCScreenW, 132) contentArray:arr1];
    
    self.menuViewB.block = ^(BOOL isSeletct ,NSString *title){
        weakself.menuViewB.hidden = YES;
        if (title.length != 0) {
            [weakself.lawView.gradeBtn setTitle:title forState:UIControlStateNormal];
        }
    };
//
    NSArray *arr2 = @[@"等级7",@"等级8",@"等级9",@"等级10",@"等级11",@"等级12"];
    self.menuViewC = [[ZZCMenuView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.lawView.regionView.frame), ZZCScreenW, 132) contentArray:arr2];
    
    self.menuViewC.block = ^(BOOL isSeletct ,NSString *title){
        weakself.menuViewC.hidden = YES;
        if (title.length != 0) {
            [weakself.lawView.regionBtn setTitle:title forState:UIControlStateNormal];
        }
    };
    self.menuViewA.hidden = YES;
    self.menuViewB.hidden = YES;
    self.menuViewC.hidden = YES;
    [self.lawView addSubview:self.menuViewA];
    self.menuViewA.y = self.lawView.rankView.y+44;
    [self.lawView addSubview:self.menuViewB];
    self.menuViewB.y = self.lawView.gradeView.y+44;
    [self.lawView addSubview:self.menuViewC];
    self.menuViewC.y = self.lawView.regionView.y+44;
    
    [self bottomBtn];
    
}


- (void)bottomBtn {
    _bbtn = [[UIButton alloc] initWithFrame:CGRectMake(0, ZZCScreenH-113, ZZCScreenW, 49)];
    _bbtn.backgroundColor = [UIColor colorWithHex:0xEA6E25];
    [_bbtn setTitle:@"重新申请" forState:0];
    [_bbtn addTarget:self action:@selector(nextClick) forControlEvents:UIControlEventTouchUpInside];
    _bbtn.titleLabel.font = FONT(19);
    [_bbtn setTag: 1120];
    [self.view addSubview:_bbtn];
}
- (void)nextClick {
    ZZCLog(@"下一步");
//    ZZCScanController *scan = [ZZCScanController new];
//    [self.navigationController pushViewController:scan animated:YES];
    ZZCLawController *law = [ZZCLawController new];
    [self.navigationController pushViewController:law animated:YES];
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    self.menuViewA.y = self.lawView.rankView.y+44 - scrollView.contentOffset.y;
    self.menuViewB.y = self.lawView.gradeView.y+44 - scrollView.contentOffset.y;
    self.menuViewC.y = self.lawView.regionView.y+44 - scrollView.contentOffset.y;
}


- (void)rankBtnClick {
    [self.view endEditing:YES];
    self.menuViewA.hidden = !self.menuViewA.hidden;
    self.menuViewB.hidden = YES;
    self.menuViewC.hidden = YES;
}
- (void)gradeBtnClick {
    [self.view endEditing:YES];
    self.menuViewB.hidden = !self.menuViewB.hidden;
    self.menuViewA.hidden = YES;
    self.menuViewC.hidden = YES;
    
}
- (void)regionBtnClick {
    [self.view endEditing:YES];
    self.menuViewC.hidden = !self.menuViewC.hidden;
    self.menuViewA.hidden = YES;
    self.menuViewB.hidden = YES;
}
#pragma mark - 值接收
- (void)textFieldDidBeginEditing:(UITextField *)textField {
    self.menuViewA.hidden = YES;
    self.menuViewB.hidden = YES;
    self.menuViewC.hidden = YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    if (textField == self.lawView.nameTextField) {
        //名字值接收,自己创建属性接收需要的值
        self.name = textField.text;
        ZZCLog(@"%@",textField.text);
    }else if (textField == self.lawView.sexTextField){
        ZZCLog(@"%@",textField.text);
    }else if (textField == self.lawView.BRbirthFLD){
        ZZCLog(@"%@",textField.text);
    }else if (textField == self.lawView.phoneTextField){
        ZZCLog(@"%@",textField.text);
    }else if (textField == self.lawView.cardTextField){
        ZZCLog(@"%@",textField.text);
    }else if (textField == self.lawView.mailboxTextField){
        ZZCLog(@"%@",textField.text);
    }
    
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
{
    if (textField == self.lawView.phoneTextField) {
        //用来做长度限制；
        if (range.location>=11) {
            return NO;
        }
    }
    if (textField == self.lawView.cardTextField) {
        //用来做长度限制；
        if (range.location>=18) {
            return NO;
        }
    }
    return YES;
    
}
-(void)messageShow {
    NSString *token = ZZCNSUserDefaults(@"token");
    NSDate *currentDate = [NSDate date];
    NSString *timeStr = [NSString stringWithFormat:@"%ld",(long)[currentDate timeIntervalSince1970]];
    NSDictionary *dict = @{
                           @"token":token,
                           @"type":@(1),
                           };
    NSString *sign = [ZZCRequest getSignWithDict:dict];
    sign = [NSString md5:[sign lowercaseString]];
    NSDictionary *param = @{
                            @"timestamp":timeStr,
                            @"sign":sign,
                            @"token":token,
                            @"type":@(1)
                            };
    NSLog(@"%@",param);
    [[ZZCRequest sharedNetworkTools] POST:ZZCURL_API_LAWYERYRMESS parameters:param finished:^(id  _Nullable responseObject, NSError * _Nullable error) {
//        NSInteger code = [responseObject[@"code"] integerValue];
        id X = responseObject;
        NSLog(@"%@",X);
        _lawView.nameTextField.text = X[@"data"][@"username"];
        _lawView.sexTextField.text = [X[@"data"][@"sex"] stringValue];
        _lawView.phoneTextField.text = X[@"data"][@"phone"];
        _lawView.BRbirthFLD.text = X[@"data"][@"birthday"];
        _lawView.cardTextField.text = X[@"data"][@"id_card"];
        _lawView.mailboxTextField.text = X[@"data"][@"email"];
//        _lawView.nameTextField.text = X[@"data"][];
        if ([[X[@"data"][@"leave"] stringValue] isEqualToString:@"1"]) {
            [self.lawView.rankBtn setTitle:@"省级" forState:UIControlStateNormal];
        } else if ([[X[@"data"][@"leave"] stringValue] isEqualToString:@"2"]) {
            [self.lawView.rankBtn setTitle:@"市级" forState:UIControlStateNormal];
        } else {
            [self.lawView.rankBtn setTitle:@"县级" forState:UIControlStateNormal];
        }
        _lawView.regionLabel.text = [NSString stringWithFormat:@"%@-%@-%@",X[@"data"][@"province"],X[@"data"][@"city"],X[@"data"][@"district"]];
        [_lawView.idCard1 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ZZCURL_API,X[@"data"][@"id_img_front"]]] placeholderImage:nil];
        [_lawView.idCard2 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ZZCURL_API,X[@"data"][@"id_img_bace"]]] placeholderImage:nil];
        [_lawView.proveView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ZZCURL_API,X[@"data"][@"img_url"]]] placeholderImage:nil];

        //
        _lawView.gradeBtn.titleLabel.text = [X[@"data"][@"word_age"] stringValue];
//        _lawView
        UIView *subView = [self.view viewWithTag:1145];
        UIButton *button = [self.view viewWithTag:1120];
        if ([[X[@"data"][@"status"] stringValue] isEqualToString:@"0"]) {
            _bbtn.hidden = YES;
            _lawView.statusLabel.text = @"   正在审核中";
            button.hidden = YES;
        } else if ([[X[@"data"][@"status"] stringValue] isEqualToString:@"1"]) {
            _lawView.statusLabel.text = @"   已通过审核";
            button.hidden = YES;
        } else if ([[X[@"data"][@"status"] stringValue] isEqualToString:@"-2"]) {
            _lawView.statusLabel.text = [NSString stringWithFormat:@"   未通过审核: %@",X[@"data"][@"remark"]];

//            _stateLabel.height = ZZCScreenH * 0.108f;
            subView.height = _lawView.statusView.height - 49;
            _bbtn.hidden = NO;
        }
//        NSLog(@"%@",responseObject[@"data"][@"status"]);
    }];
}
- (ZZCLawView *)lawView {
    if (_lawView == nil) {
        _lawView = [ZZCLawView lawView];
        _lawView.frame = CGRectMake(0, 0, ZZCScreenW, ZZCScreenH);
        _lawView.nameTextField.delegate = self;
        _lawView.sexTextField.delegate = self;
        _lawView.BRbirthFLD.delegate = self;
        _lawView.phoneTextField.delegate = self;
        _lawView.cardTextField.delegate = self;
        _lawView.mailboxTextField.delegate = self;
        
    }
    return _lawView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
